package com.mySampleApplication.server;

import cn.hutool.db.Db;
import cn.hutool.db.DbUtil;
import cn.hutool.db.Entity;
import cn.hutool.db.ds.DSFactory;
import cn.hutool.db.handler.EntityListHandler;
import cn.hutool.db.sql.SqlExecutor;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test {

    public static void main(String[] args) {
        //testMysql();
        Map<String,String> map = new HashMap<>();
        map.put("object_id","233e4f3565c10c6b79b6f83ebea2e176");
        new DmpServlet().getSelectByObjectId(map,"bt_data_object_attribute");
    }
    public void getTest(){
        // 获取主库连接
        DataSource db = DbUtil.getDs("default");

        // 获取从库连接
        //Db db2 = DbUtil.getDb("slave");
    }

    /**
     * 测试mysql
     */
    private static void testMysql() {
        DataSource ds = DSFactory.get("mysql1");
        Db.use(ds);
        Connection conn = null;
        try {
            conn = ds.getConnection();
            /*// 插入语句
            SqlExecutor.execute(conn, "insert into t_user (name,age) value ('小张',35)");
            // 更新语句
            SqlExecutor.execute(conn, "update t_user set name='小明002' where id=2 ");
            // 删除语句
            SqlExecutor.execute(conn, "delete from t_user  where id=2 ");*/
            List<Entity> entityList = SqlExecutor.query(conn, "select count(*) as total from sys_user", new EntityListHandler());
            for (Entity entity : entityList) {
                System.out.println(entity.get("total"));
            }
        } catch (SQLException e) {

        } finally {
            DbUtil.close(conn);
        }
    }

}
